package vn.edu.saigontech.ncms.web.education;

import java.util.Collection;

import vn.edu.saigontech.ncms.model.enumeration.Gender;
import vn.edu.saigontech.ncms.model.info.Student;
import vn.edu.saigontech.ncms.service.EducationService;
import vn.edu.saigontech.ncms.service.ProgramService;
import vn.edu.saigontech.ncms.service.StudentService;
import vn.edu.saigontech.ncms.util.DateUtil;
import vn.edu.saigontech.ncms.web.BaseAction;

@SuppressWarnings("serial")
public class EducationAction extends BaseAction {
	
	private Long studentId;
	private String firstName;
	private String lastName;
	private String gender;
	private String dateOfBirth;
	private Long levelId;
	private Long offeringId;
	private String receiptNo;
	private Integer type;
	
	public String showAllStudents() {
		REQUEST().setAttribute("students", EducationService.INSTANCE.findStudents());
		return SUCCESS;
	}
	
	public String searchByFirstName() {
		try {
		REQUEST().setAttribute("students", EducationService.INSTANCE.findByFirstName(this.firstName, this.type));
		} catch (Exception e) {
			throw new NullPointerException();
		}
		return SUCCESS;
	}
	
	public String reportStudy() {
		REQUEST().setAttribute("students", EducationService.INSTANCE.findByFirstName(this.firstName, this.type));
		return SUCCESS;
	}
	
	public String showStudentInfo() {
		REQUEST().setAttribute("student", StudentService.INSTANCE.findById(this.studentId));
		return SUCCESS;
	}
	
	public String showStudentSearch() {
		REQUEST().setAttribute("programs", ProgramService.INSTANCE.findAllAreActive());
		return SUCCESS;
	}
	
	public String searchStudent() {
		Collection<Student> students = EducationService.INSTANCE.findStudents(this.firstName, 
				this.lastName, 
				Gender.create(this.gender), 
				DateUtil.fromString(this.dateOfBirth, this.i18n("format.date")), 
				this.levelId, 
				this.offeringId, 
				this.receiptNo);
		REQUEST().setAttribute("students", students);
		return SUCCESS;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public Long getStudentId() {
		return studentId;
	}

	public void setStudentId(Long studentId) {
		this.studentId = studentId;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getDateOfBirth() {
		return dateOfBirth;
	}

	public void setDateOfBirth(String dateOfBirth) {
		this.dateOfBirth = dateOfBirth;
	}

	public Long getLevelId() {
		return levelId;
	}

	public void setLevelId(Long levelId) {
		this.levelId = levelId;
	}

	public Long getOfferingId() {
		return offeringId;
	}

	public void setOfferingId(Long offeringId) {
		this.offeringId = offeringId;
	}

	public String getReceiptNo() {
		return receiptNo;
	}

	public void setReceiptNo(String receiptNo) {
		this.receiptNo = receiptNo;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}
}
